<?php
    /** 
     * @author Anton Perkin
     * 
     * 
     */
    class Language
    {
        /* VARIABLES */
        
        /**
         * Current language name
         * @var string
         */
        static private $name;
        
        /**
         * Current language short name
         * @var string
         */
        static private $shortName;
        
        
        /* FUNCTIONS */
        
    	/**
		 * Gets the translation
		 * 
		 * @param $name the name of element to translate
		 * @param $modifier modifier name. Allowed modifiers are: CAPITALIZE, UPPERCASE, LOWERCASE
		 * @param array $parameters parameters. Used if the translation text has the parameters ({%i})
		 * 
		 * @return translation for the given element
		 */
		public static function Get($name, $modifier = '', array $parameters = array())
		{
			//checks whether the translation exists
		    if (!defined('LANG_'.strtoupper(str_replace(' ', '_', $name))))
		    {
		        return $name;
		    }
			
		    //gets the translation  
		    $result = constant('LANG_'.strtoupper(str_replace(' ', '_', $name)));

		    //if modifiers are applied
    		if (!empty($modifier))
    		{
    			switch ($modifier)
    			{
    				//makes the first letter upper-case
    				case 'CAPITALIZE':
    					$result = ucfirst($result);
    					break;
    
    				//makes the whole expression upper-case
    				case 'UPPERCASE':
    					$result = strtoupper($result);
    					break;
    
    				//makes the whole expression lower-case	
    				case 'LOWERCASE':
    					$result = strtolower($result);
    					break;
    					
    				default:
    				    break;	
    			}
    		}
    		
    		//if parametrized translation is performed
			if (!empty($parameters))
	        {
    	        $i = 1;
                foreach ($parameters as $parameter)
                {
                    $result = str_replace('{%'.$i.'}', $parameter, $result);
                    $i++;
                }
	        }    		

			return $result;
		}        
	
		
		/* GETTERS/SETTERS */
		
    	/**
    	 * @return the $name
    	 */
    	public static function getName()
    	{
    		return language::$name;
    	}
    
    	/**
    	 * @return the $shortName
    	 */
    	public static function getShortName()
    	{
    		return language::$shortName;
    	}
    
    	/**
    	 * @param $name the $name to set
    	 */
    	public static function setName($name)
    	{
    		language::$name = $name;
    	}
    
    	/**
    	 * @param $shortName the $shortName to set
    	 */
    	public static function setShortName($shortName)
    	{
    		language::$shortName = $shortName;
    	}

    }
?>